package com.qf.service.impl;

import com.qf.constant.RabbitMQConstants;
import com.qf.model.StandardSubmit;
import com.qf.service.Strategy;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 路由策略/流量控制
 * @author 何星宇
 * @version V1.0
 * @Date 2021/11/23 19:32
 */

@Service(value = "router")
@Slf4j
public class RouterStrategy implements Strategy {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Override
    public boolean strategy(StandardSubmit standardSubmit) {
        //记录日志
        log.info("【策略模块-路由策略】 开始执行！");

        //发送消息到指定队列
        rabbitTemplate.convertAndSend(RabbitMQConstants.TOPIC_SMS_GATEWAY+standardSubmit.getGatewayID(), standardSubmit);

        //记录日志
        log.info("【策略模块-路由策略】 路由完成！");
        return true;
    }
}
